﻿using System.Reflection;
using System.Xml.Linq;
using System;

namespace WF.Web
{
    public class ConfigHelper
    {
        XElement _xFile = null;
        XElement _ele = null;
        private string _xmlPath = Assembly.GetExecutingAssembly().CodeBase.Split(new string[] { "bin" }, StringSplitOptions.RemoveEmptyEntries)[0] + "xml/config.xml";

        public ConfigHelper()
        {
            _xFile = XElement.Load(_xmlPath);
        }

        private string _departmentLimite = string.Empty;
        public string DepartmentLimite
        {
            get
            {
                _ele = _xFile.Element("DepartmentLimit");
                _departmentLimite = _ele.Value;
                return _departmentLimite;
            }
            set
            {
                _ele = _xFile.Element("DepartmentLimit");
                _ele.SetValue(value);
                _xFile.Save(_xmlPath.Replace("file:///", ""));
            }
        }

        private string _employeeLimite = string.Empty;
        public string EmployeeLimite
        {
            get
            {
                _ele = _xFile.Element("EmployeeLimit");
                _departmentLimite = _ele.Value;
                return _departmentLimite;
            }
            set
            {
                _ele = _xFile.Element("EmployeeLimit");
                _ele.SetValue(value);
                _xFile.Save(_xmlPath.Replace("file:///", ""));
            }
        }

        private string _hrBlockLimite = string.Empty;
        public string HrBlockLimite
        {
            get
            {
                _ele = _xFile.Element("HrBlockLimit");
                _hrBlockLimite = _ele.Value;
                return _hrBlockLimite;
            }
            set
            {
                _ele = _xFile.Element("HrBlockLimit");
                _ele.SetValue(value);
                _xFile.Save(_xmlPath.Replace("file:///", ""));
            }
        }

        private string _commonCode = string.Empty;
        public string CommonCode
        {
            get
            {
                _ele = _xFile.Element("CommonCode");
                _commonCode = _ele.Value;
                return _commonCode;
            }
            set
            {
                _ele = _xFile.Element("CommonCode");
                _ele.SetValue(value);
                _xFile.Save(_xmlPath.Replace("file:///", ""));
            }
        }

        private string _reportGroups = string.Empty;
        public string ReportGroups
        {
            get
            {
                _ele = _xFile.Element("ReportGroups");
                _reportGroups = _ele.Value;
                return _reportGroups;
            }
            set
            {
                _ele = _xFile.Element("ReportGroups");
                _ele.SetValue(value);
                _xFile.Save(_xmlPath.Replace("file:///", ""));
            }
        }
    }
}